<?php
include '../template.php';
include '../dbconfig/config.php';
include '../dbconfig/opendb.php';
include './peptideformat.php';
include '../util/dbutil.php';
getTopWithJS("..");
?>

&nbsp;<br />

<?php

        if(isset($_GET['id'])) {
            $ids = array_unique(explode(",",$_GET['id']));
	} else {
            die('Phosphosite information not available!');
        }

        foreach ($ids as $id) {
            $query = "SELECT DISTINCT phosphoSequence,sequence,protein,location ".
                     "FROM peptide ".
                     "WHERE peptide.mass=$id";
            $result = mysql_query($query) or die("Error, query failed--$query");
            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $pnrseq = $row['phosphoSequence'];
                $linkformat = str_replace('#', '%23', $pnrseq);
                $formated = format_nr_pep_colored_sites($pnrseq);
                $protId = $row['protein'];
                $loc = $row['location'];
                $peplinks[] = "<a href=\"../data/peptide.php?pnrseq=$linkformat&pro=$protId&loc=$loc\">$formated</a>";
                $pepseq[] = $row['sequence'];
            }

            $query = "SELECT dataSource,file,scan,level,retent,ISNULL(mz) as nullMass FROM mass WHERE id=$id";
            $result = mysql_query($query) or die("Error, query failed--$query");
            $row = mysql_fetch_array($result, MYSQL_ASSOC);
            if ($row) {
                $dslink = getDataSourceLink($row['dataSource']);
                $scan = $row['file'].'.'.$row['scan'];
                $level = $row['level'];
                $retent = $row['retent'];
                $nullMass = $row['nullMass'];
            }

            echo "<table>";
            if (isset($row['scan'])) {
                echo "<tr><td align=\"right\"><b>Scan:</b></td><td>&nbsp;</td><td>".$scan;
                if (!$nullMass) {
                    echo "&nbsp;&nbsp;";
                    echo  "<a href=\"./spectrum/view_spectrum.php?msid={$id}\" target=\"_blank\">View annotated spectrum</a>";
                }
                echo "</td></tr>";
            }
            echo "<tr><td align=\"right\"><b>Reference:</b></td><td>&nbsp;</td><td>".$dslink."</td></tr>";
            if (isset($level))
            echo "<tr><td align=\"right\"><b>MS Level:</b></td><td>&nbsp;</td><td>".$level."</td></tr>";
            if (isset($retent))
                echo "<tr><td align=\"right\"><b>Retention Time:</b></td><td>&nbsp;</td><td>".$retent."</td></tr>";
            echo "<tr valign=\"top\"><td align=\"right\"><b>Peptides:</b></td><td>&nbsp;</td><td>".implode($peplinks,'<br/>')."</td></tr>";

            echo "</table>";
            echo "<hr/>";
        }

	include '../dbconfig/closedb.php';
?>
	
	

<?php getBottom(); ?>
